import 'package:equatable/equatable.dart';
import 'package:backend.core/core/domain/entities/api/google_play/api_google_play_purchased_subscription_cancellation_survey_result.dart';
import 'package:backend.purchases/infrastructure/dtos/api/google_play/api_google_play_purchased_subscription_cancellation_survey_reason_dto.dart';

const kApiGooglePlayPurchasedSubscriptionCancellationSurveyReasonKey = 'reason';
const kApiGooglePlayPurchasedSubscriptionCancellationSurveyCustomAnswerKey = 'custom_answer';

class ApiGooglePlayPurchasedSubscriptionCancellationSurveyResultDto extends Equatable {
  const ApiGooglePlayPurchasedSubscriptionCancellationSurveyResultDto._internal({
    required this.reasonDto,
    required this.customAnswer,
  });

  final ApiGooglePlayPurchasedSubscriptionCancellationSurveyReasonDto reasonDto;
  final String? customAnswer;

  @override
  List<Object?> get props {
    return [
      reasonDto,
      customAnswer,
    ];
  }

  factory ApiGooglePlayPurchasedSubscriptionCancellationSurveyResultDto.fromEntity(
      ApiGooglePlayPurchasedSubscriptionCancellationSurveyResult surveyResult) {
    final reasonDto = ApiGooglePlayPurchasedSubscriptionCancellationSurveyReasonDto.fromEntity(
        surveyResult.reason);

    return ApiGooglePlayPurchasedSubscriptionCancellationSurveyResultDto._internal(
      reasonDto: reasonDto,
      customAnswer: surveyResult.customAnswer,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      kApiGooglePlayPurchasedSubscriptionCancellationSurveyReasonKey: reasonDto.toString(),
      kApiGooglePlayPurchasedSubscriptionCancellationSurveyCustomAnswerKey: customAnswer,
    };
  }
}
